import type { ElementHiderRuleConfig } from '../../../types/constants'
import { PageHandler } from '../../../lib/page_handler'
import { BianPageType } from '../../../lib/page_handler/platform/bian/types'
import { ElementSelectorPosition, ElementSelectorType } from '../../../types/constants'
import { ELEMENT_IDENTIFIER_CONFIG } from '../../service/element_identifier/types'
import { addPrefixToConfig } from '../element_config'

export const BIAN_LIST_PAGE_ELEMENT_CONFIG: ElementHiderRuleConfig = {
  [ELEMENT_IDENTIFIER_CONFIG.default.carousel.id]: {
    hide: false,
    selectorType: ElementSelectorType.Mix,
    selector: '#main .slide',
    position: ElementSelectorPosition.TopCenter,
    enable: () => {
      const supportPages = [
        BianPageType.List,
      ]
      return supportPages.includes(PageHandler.getCurrentPageType() as BianPageType)
    },
  },
  [ELEMENT_IDENTIFIER_CONFIG.pagination.nextPage.id]: {
    hide: false,
    selectorType: ElementSelectorType.Mix,
    selector: '#main .slist ul li.nextpage',
    position: ElementSelectorPosition.MiddleCenter,
    enable: () => {
      const supportPages = [
        BianPageType.List,
      ]
      return supportPages.includes(PageHandler.getCurrentPageType() as BianPageType)
    },
  },
  [ELEMENT_IDENTIFIER_CONFIG.ad.contentAd.id]: {
    hide: true,
    selectorType: ElementSelectorType.Complex,
    selector: '#main .page + div:has(img)',
    position: ElementSelectorPosition.BottomCenter,
    enable: () => {
      const supportPages = [
        BianPageType.List,
      ]
      return supportPages.includes(PageHandler.getCurrentPageType() as BianPageType)
    },
  },
  [ELEMENT_IDENTIFIER_CONFIG.default.friendLink.id]: {
    hide: false,
    selectorType: ElementSelectorType.Complex,
    selector: '.wrap > .link',
    position: ElementSelectorPosition.BottomCenter,
    enable: () => {
      const supportPages = [
        BianPageType.List,
      ]
      return supportPages.includes(PageHandler.getCurrentPageType() as BianPageType)
    },
  },
  [ELEMENT_IDENTIFIER_CONFIG.default.footer.id]: {
    hide: false,
    selectorType: ElementSelectorType.Id,
    selector: '#footer',
    position: ElementSelectorPosition.BottomCenter,
    enable: () => {
      const supportPages = [
        BianPageType.List,
      ]
      return supportPages.includes(PageHandler.getCurrentPageType() as BianPageType)
    },
  },
  [ELEMENT_IDENTIFIER_CONFIG.default.backTop.id]: {
    hide: false,
    selectorType: ElementSelectorType.Class,
    selector: '.gotop',
    position: ElementSelectorPosition.BottomRight,
    enable: () => {
      const supportPages = [
        BianPageType.List,
      ]
      return supportPages.includes(PageHandler.getCurrentPageType() as BianPageType)
    },
  },
}

export const BIAN_DETAIL_PAGE_ELEMENT_CONFIG: ElementHiderRuleConfig = {
  [ELEMENT_IDENTIFIER_CONFIG.default.tag.id]: {
    hide: false,
    selectorType: ElementSelectorType.Mix,
    selector: '#main .photo .photo-tags',
    position: ElementSelectorPosition.MiddleCenter,
    enable: () => {
      const supportPages = [
        BianPageType.Detail,
      ]
      return supportPages.includes(PageHandler.getCurrentPageType() as BianPageType)
    },
  },
  [ELEMENT_IDENTIFIER_CONFIG.default.share.id]: {
    hide: false,
    selectorType: ElementSelectorType.Mix,
    selector: '#main .photo .share',
    position: ElementSelectorPosition.MiddleCenter,
    enable: () => {
      const supportPages = [
        BianPageType.Detail,
      ]
      return supportPages.includes(PageHandler.getCurrentPageType() as BianPageType)
    },
  },
  [ELEMENT_IDENTIFIER_CONFIG.ad.contentAd.id]: {
    selectorType: ElementSelectorType.Multiple,
    selector: '#main > div:not([class]):has(> a), #main .side .infor + div:has(> a), .wrap .photopx .photops',
    position: ElementSelectorPosition.BottomCenter,
    hide: true,
    enable: () => {
      const supportPages = [
        BianPageType.Detail,
      ]
      return supportPages.includes(PageHandler.getCurrentPageType() as BianPageType)
    },
  },
  [ELEMENT_IDENTIFIER_CONFIG.default.moreRecommend.id]: {
    hide: false,
    selectorType: ElementSelectorType.Mix,
    selector: '.wrap .photopx .slist',
    position: ElementSelectorPosition.BottomCenter,
    enable: () => {
      const supportPages = [
        BianPageType.Detail,
      ]
      return supportPages.includes(PageHandler.getCurrentPageType() as BianPageType)
    },
  },
  [ELEMENT_IDENTIFIER_CONFIG.default.footer.id]: {
    hide: false,
    selectorType: ElementSelectorType.Id,
    selector: '#footer',
    position: ElementSelectorPosition.BottomCenter,
    enable: () => {
      const supportPages = [
        BianPageType.Detail,
      ]
      return supportPages.includes(PageHandler.getCurrentPageType() as BianPageType)
    },
  },
  [ELEMENT_IDENTIFIER_CONFIG.default.backTop.id]: {
    hide: false,
    selectorType: ElementSelectorType.Class,
    selector: '.gotop',
    position: ElementSelectorPosition.BottomRight,
    enable: () => {
      const supportPages = [
        BianPageType.Detail,
      ]
      return supportPages.includes(PageHandler.getCurrentPageType() as BianPageType)
    },
  },
}

/**
 * 所有配置
 */
export const BIAN_WEB_ELEMENT_CONFIG: ElementHiderRuleConfig = {
  ...addPrefixToConfig(BIAN_LIST_PAGE_ELEMENT_CONFIG, 'list'),
  ...addPrefixToConfig(BIAN_DETAIL_PAGE_ELEMENT_CONFIG, 'detail'),
}
